package com.lzb.compressmaster.fragment;

import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.blankj.utilcode.util.AppUtils;
import com.blankj.utilcode.util.CleanUtils;
import com.blankj.utilcode.util.ToastUtils;
import com.lzb.compressmaster.BaseApplication;
import com.lzb.compressmaster.BaseNoModelFragment;
import com.lzb.compressmaster.R;
import com.lzb.compressmaster.activity.FeedbackActivity;
import com.lzb.compressmaster.activity.WebActivity;
import com.lzb.compressmaster.databinding.FragmentMyBinding;

/**
 * A simple {@link Fragment} subclass.
 * Use the {@link MyFragment#newInstance} factory method to
 * create an instance of this fragment.
 */
public class MyFragment extends BaseNoModelFragment<FragmentMyBinding> implements View.OnClickListener {


    @Override
    protected int onCreate() {
        return R.layout.fragment_my;
    }

    @Override
    protected void initView() {
        mDataBinding.llFeedback.setOnClickListener(this);
        mDataBinding.llAbout.setOnClickListener(this);
        mDataBinding.llAgreement.setOnClickListener(this);
        mDataBinding.llPrivacy.setOnClickListener(this);
        mDataBinding.llRevoke.setOnClickListener(this);
        mDataBinding.llPermission.setOnClickListener(this);
        mDataBinding.llClearCache.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        int id = view.getId();
        if (id == R.id.llFeedback) {//意见反馈
            startActivity(FeedbackActivity.class);
        } else if (id == R.id.llAbout) {//关于我们

        } else if (id == R.id.llAgreement) {//用户协议
            Intent bundle = new Intent(getActivity(), WebActivity.class);
            bundle.putExtra("type", 0);
            startActivity(bundle);
        } else if (id == R.id.llPrivacy) {//隐私政策
            Intent bundle = new Intent(getActivity(), WebActivity.class);
            bundle.putExtra("type", 1);
            startActivity(bundle);
        } else if (id == R.id.llRevoke) {//授权撤销
            // 设置跳过下次启动页跳转，因为从应用详情页面返回时不应该跳转到启动页
            BaseApplication.setSkipSplashOnNextStart(true);
            AppUtils.launchAppDetailsSettings();
        } else if (id == R.id.llPermission) {//权限管理
            // 设置跳过下次启动页跳转，因为从应用详情页面返回时不应该跳转到启动页
            BaseApplication.setSkipSplashOnNextStart(true);
            AppUtils.launchAppDetailsSettings();
        } else if (id == R.id.llClearCache) {//清除缓存
            CleanUtils.cleanInternalCache();
            ToastUtils.showShort(getString(R.string.clear_suc));
        }
    }

    @Override
    protected void initData() {

    }


    @Override
    public FrameLayout getNativeView() {
        return mDataBinding.adContainer;
    }
}